(define-module (mach port-destruction)
  #:use-module (mach ffi)
  #:use-module (mach types)
  #:use-module (mach task))

;;
;; This file implements all the port destruction functions.
;;

(define-ffi ("mach_port_deallocate" %mach-port-deallocate!)
  (err identity) ; XXX ???
  (task ffi:ipc-space %unwrap-ipc-space)
  ;; XXX figure out the name / port distinction
  (name ffi:mach-port %unwrap-mach-port))

(define* (port-deallocate! name #:optional (task (task-self)))
  ;; XXX do we mean port or name here?
  "Deallocate a port @var{name} the ipc namespace @var{task}."
  (%mach-port-deallocate! task name))

(define-ffi ("mach_port_destroy" %mach-port-destroy!)
  (err identity) ; XXX ?
  (task ffi:ipc-space %unwrap-ipc-space)
  (port-name ffi:mach-port %unwrap-mach-port))

;; XXX mention TASK.
(define* (port-destroy! port-name #:optional (task (task-self)))
  "Deallocate all rights denoted by a port name. The name becomes immediately available for reuse."
  (%mach-port-destroy! task port-name))


